package com.example.mobile2021606140lhq0420;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class PartRVAdapter extends RecyclerView.Adapter<PartRVAdapter.ViewHoldeer>{

    int[] partIds;
    String[] partNames;
    public PartRVAdapter(int[] partIds, String[] partNames) {
        this.partIds=partIds;
        this.partNames=partNames;
    }

    @NonNull
    @Override
    public ViewHoldeer onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(
                R.layout.item_rv_main_part,parent,false);
        return new ViewHoldeer(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHoldeer holder, int position) {
        holder.ivPart.setImageResource(partIds[position]);
        holder.tvPart.setText(partNames[position]);
    }

    @Override
    public int getItemCount() {
        return partIds.length;
    }

    static class ViewHoldeer extends RecyclerView.ViewHolder{
        ImageView ivPart;
        TextView tvPart;
    public ViewHoldeer(View itemView) {
        super(itemView);
        this.ivPart = itemView.findViewById(R.id.iv_item_part);
        this.tvPart = itemView.findViewById(R.id.tv_item_part);
    }
    }
}
